package my

import (
	"beergo/app/check/conf"
	"beergo/lib/tool"
	"github.com/beego/beego/v2/server/web"
)

func init() {
	web.Router(conf.UrlPrefix + "/Org/my", &CheckMyController{}, "*:MyOrgAction")
	web.Router(conf.UrlPrefix + "/Org/apply", &CheckMyController{}, "*:ApplyOrgAction")
}

func (this *CheckMyController) MyOrgAction() {
	user:=this.GetUser()
	org:=this.Repository.FindOneBy(tool.M{"user":user.Id},[]string{"-id"})
	this.ReturnSuccess("数据获取成功",org.Scan("",2,""))
}

func (this *CheckMyController) ApplyOrgAction() {
	entity := this.Model.New()
	_, err := this.JsonParseModel(entity)
	this.AnaliseErrors(err)
	user:=this.GetUser()
	entity.User = &user
	_, errSave := entity.Save()
	this.AnaliseErrors(errSave)
	//绑定用户
	this.FillM2M(entity)
	this.ReturnSuccess("OK", entity.Id)
}